/*
 * 作者:熊猫
 * 日期:2017 - 3 - 17 10 - 20 - 45
 *
 */

package net.lainiao.morethread.Chapter7.demo5;

import java.util.concurrent.RunnableScheduledFuture;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/17.
 */
public class MyScheduledThreadPoolExectutor extends ScheduledThreadPoolExecutor {
    public MyScheduledThreadPoolExectutor(int corePoolSize) {
        super(corePoolSize);
    }

    @Override
    protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task) {
        MyScheduledTask<V> myTask=new MyScheduledTask<V>(runnable,null,task,this);
        return myTask;
    }

    @Override
    public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
        ScheduledFuture<?> task=super.scheduleAtFixedRate(command,initialDelay,period,unit);
        MyScheduledTask<?> myTask=(MyScheduledTask<?>) task;
        myTask.setPeriod(TimeUnit.MILLISECONDS.convert(period,unit));
        return task;
    }




}
